package com.ziyun.erp.web.api.logistics;

import com.ziyun.erp.common.utils.JsonUtils;
import com.ziyun.erp.modules.logistics.dto.ErpLogisticsDto;
import com.ziyun.erp.modules.logistics.service.ErpLogisticsService;
import com.ziyun.erp.modules.logistics.service.LogisticsTypeService;
import com.ziyun.erp.modules.production.service.ErpOrderProductionService;
import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * 物流配送表
 *
 * @author llc
 * @email ...
 * @date 2018-09-21 16:12:35
 */
@RestController
@RequestMapping("port/logistics/erplogistics")
public class ErpLogisticsControllerApi {
    @Autowired
    private ErpLogisticsService erpLogisticsService;

    @Autowired
    private LogisticsTypeService logisticsTypeService;
    @Autowired
    private ErpOrderProductionService erpOrderProductionService;

    /**
     * 保存 订单物流信息
     */
    @RequestMapping("/saveOrderLogisticsInfo")
    public R saveOrderLogisticsInfo(@RequestBody Map<String, Object> paramBodyMap){
        ErpLogisticsDto erpLogisticsDto = JsonUtils.string2Object(paramBodyMap.get("erpLogisticsDto").toString(),ErpLogisticsDto.class);
        String createName = paramBodyMap.get("createName").toString();
        String userId = paramBodyMap.get("userId").toString();
        return erpLogisticsService.saveOrderLogisticsInfo(erpLogisticsDto, userId, createName);
    }

    //查询物流方式
    @RequestMapping("/queryLogisticTypeList")
   public R queryLogisticTypeList(){
        List<Map<Integer,String>> logisticsTypeList= logisticsTypeService.queryTypeList();
        return R.ok().put("logisticsTypeList",logisticsTypeList);
    }

    /**
     * 快递单寄件收件人信息
     */
    @RequestMapping("/expressFormInfo")
    public R expressFormInfo(@RequestBody Map<String, Object> paramBodyMap){
        String orderNo = (String) paramBodyMap.get("orderNo");
        return erpOrderProductionService.queryExpressFormInfo(orderNo);
    }

}
